<h2>Invoice Summary</h2>
<h2><?php echo $owner->getListName()?></h2>
<h3>From <?php echo date('m/d/Y',strtotime($from_date))?> To <?php echo date('m/d/Y',strtotime($to_date))?></h3>
<?php $total_invoice = 0;?>
<?php $total_debit = 0;?>
<?php $total_credit = 0;?>
<?php $total_payment = 0;?>
<?php $total_others = 0;?>
<?php $total_receivables = 0;?>
<table class="form">
  <tr>
    <th>Customer Name:</th>
    <td><?php echo $contact->getListName()?></td>
  </tr>
  <tr>
    <th>Address:</th>
    <td><?php echo nl2br($contact->getCityAddress())?></td>
  </tr>
  <tr>
    <th>Phone:</th>
    <td><?php echo $contact->getPhone()?></td>
  </tr>
</table>
<hr/>
<table class="datagrid" id="gridInvoiceSearch">
  <thead class="datagrid">
    <tr>
      <th style="width:50px;">Issued on</th>
      <th style="width:100px;">Invoice</th>
      <th style="width:200px;">Invoice Name</th>
      <th style="width:75px;text-align:right;">Total</th>
      <th style="width:75px;text-align:right;">Debit</th>
      <th style="width:75px;text-align:right;">Credit</th>
      <th style="width:75px;text-align:right;">Payment</th>
      <th style="width:75px;text-align:right;">Others</th>
      <th style="width:75px;text-align:right;">Balance</th>
    </tr>
  </thead>
  <tbody class="datagrid" style="height:auto;">
    <?php foreach($invoices as $invoice):?>
      <tr>
        <td><?php echo $invoice->getIssueDate()?></td>
        <td><?php echo $invoice->getInvoiceType().'-'.$invoice->getInvoiceId()?></td>
        <td><?php echo $invoice->getInvoiceName()?></td>
        <td style="text-align:right;"><?php echo number_format($invoice->getTotal(),2)?></td>
        <?php $transaction_list = $invoice->getTransactions()?>
        <td style="text-align:right;"><?php echo number_format($transaction_list['DEBIT MEMO'],2)?></td>
        <td style="text-align:right;"><?php echo number_format($transaction_list['CREDIT MEMO'],2)?></td>
        <td style="text-align:right;"><?php echo number_format($transaction_list['PAYMENT'],2)?></td>
        <td style="text-align:right;"><?php echo number_format($transaction_list['OTHERS'],2)?></td>
        <td style="text-align:right;"><?php echo number_format($invoice->getTotal()+$transaction_list['DEBIT MEMO']+$transaction_list['CREDIT MEMO']+$transaction_list['PAYMENT']+$transaction_list['OTHERS'],2)?></td>
      </tr>
      <?php $total_invoice += $invoice->getTotal();?>
      <?php $total_debit += $transaction_list['DEBIT MEMO'];?>
      <?php $total_credit += $transaction_list['CREDIT MEMO'];?>
      <?php $total_payment += $transaction_list['PAYMENT'];?>
      <?php $total_others += $transaction_list['OTHERS'];?>
      <?php $total_receivables += $invoice->getTotal()+$transaction_list['DEBIT MEMO']+$transaction_list['CREDIT MEMO']+$transaction_list['PAYMENT']+$transaction_list['OTHERS'];?>
    <?php endforeach;?>
  </tbody>
  <tfoot class="datagrid">
      <tr>
        <td colspan="3">TOTAL</td>
        <td style="text-align:right;"><?php echo number_format($total_invoice,2) ?></td>
        <td style="text-align:right;"><?php echo number_format($total_debit,2) ?></td>
        <td style="text-align:right;"><?php echo number_format($total_credit,2) ?></td>
        <td style="text-align:right;"><?php echo number_format($total_payment,2) ?></td>
        <td style="text-align:right;"><?php echo number_format($total_others,2) ?></td>
        <td style="text-align:right;"><?php echo number_format($total_receivables,2) ?></td>
      </tr>
  </tfoot>
</table>

